/**
 * Created by abdulazizalonizi on 7/31/17.
 */
import java.util.Scanner ;
public class Task4 {
    public static void main (String[] args)
    {
        Scanner kb = new Scanner (System.in);
        System.out.println("enter Matrix A Dimensions");
        int A_row = kb.nextInt();
        int A_col = kb.nextInt();



        System.out.println("enter Matrix B Dimensions");
        int B_row = kb.nextInt();
        int B_col = kb.nextInt();


        if (A_col != B_row) {
            System.out.println("Cannot Multiply , Program Terminated !");
            System.exit(0);
        }


        int A[][] = new int [A_row][A_col];
        int B[][] = new int [B_row][B_col];

        for (int i = 0 ; i < A_row ; i++){
            for (int j = 0 ; j < A_col ; j++)
            {
                System.out.println("fill the array A row wise ");
                A[i][j]=kb.nextInt();

            }

        }

        for (int i = 0 ; i < B_row ; i++){
            for (int j = 0 ; j < B_col ; j++)
            {
                System.out.println("fill the array B row wise ");
                B[i][j]=kb.nextInt();

            }

        }




        int C[][] = new int [A.length][B[0].length];

        for (int r = 0 ; r < A.length ; r++)
        {
            for (int c =0 ;c< B[0].length ; c++)
            {
                for(int k = 0 ; k <B.length ;k++)
                C[r][c] += A[r][k]*B[k][c];
            }

        }

        for (int i = 0 ; i <C.length; i++)
        {
            for (int j = 0 ; j < C[i].length ; j++)
            {
                System.out.print(C[i][j]+" ");
            }
        System.out.println(" ");
        }

    }
}
